<!--
 * @Author: Luxiaoxiang
 * @Date: 2022-10-11 22:42:44
 * @LastEditors: lxx
 * @LastEditTime: 2022-10-24 17:02:48
 * @Description:
 * @FilePath: \briup-ui\src\pages\admin\check\InfoComment.vue
-->
<template>
  <!-- 资讯评论审核 -->
  <div>
    <!-- 第一行 -->
    <div class="header">
      <el-form :inline="true" :model="params" class="demo-form-inline">
        <el-form-item>
          <el-button
            type="primary"
            @click="toDeletAll"
          >批量删除</el-button>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="params.keywords"
            placeholder="请输入评论内容"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 第一行 结束 -->

    <!-- 第二行 表格 -->
    <el-table
      ref="multipleTable"
      :data="infoData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" />
      <el-table-column type="index" label="序号" />
      <el-table-column prop="comment" label="评论内容" />
      <el-table-column prop="userId" label="评论人编号" show-overflow-tooltip />
      <el-table-column prop="articleId" label="资讯编号" />
      <el-table-column prop="commentTime" label="评论时间">
        <template slot-scope="scope">
          <span>{{ scope.row.commentTime |fmtDate }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="评论状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === '通过'">通过</el-tag>
          <el-tag v-else-if="scope.row.status === '未审核'" type="info">未审核</el-tag>
          <el-tag v-else type="danger">不通过</el-tag>

        </template>
      </el-table-column>
     
      <el-table-column label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click.prevent="deleteComment(scope.row)">
            <el-tag type="danger"> 删除</el-tag>
          </a>
        </template>
      </el-table-column>
    </el-table>

    <!-- 第二行 表格结束 -->

    <!-- 第三行 分页按钮 -->
    <div class="bottom">
      <el-pagination
        class="page"
        :current-page="params.page"
        :page-sizes="[2, 5, 8, 20, 30]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />

    </div>

  </div>
</template>

<script>
import { InfoComment, deleteAll } from '../../../api/infoComment'
import { get } from '../../../utils/request'
export default {
  data() {
    return {
      params: {
        page: 1,
        pageSize: 10
      },
      infoData: [],
      total: 0,
      ids: []

    }
  },
  computed: {},
  created() {
    this.getComments()
  },
  mounted() {},
  methods: {

    async getComments() {
      for (const key in this.params) {
        if (!this.params[key]) {
          delete this.params[key]
        }
      }
      const res = await InfoComment(this.params)
      console.log(res, '获取响应')
      this.infoData = res.data.list
      this.total = res.data.total
      console.log(this.total, '444')
    },

    toSearch() {
      this.params.page = 1
      this.getComments()
    },

    // 页码条数发生改变的方法 默认参数pageSize
    handleSizeChange(pageSize) {
      // 当前页码发生改变的方法
      this.params.pageSize = pageSize
      this.params.page = 1
      this.getComments()
    },
    // 当前页码发生改变的方法 默认参数页码page
    handleCurrentChange(page) {
      this.params.page = page
      this.getComments()
    },

    // 批量删除
    handleSelectionChange(val) {
      this.ids = val.map((item) => item.id)
      this.ids = this.ids.toString()
    },
    toDeletAll() {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await deleteAll({ ids: this.ids })
        this.$message({
          type: 'success',
          message: res.message
        }),

        this.getComments()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消我们的操作'
        })
      })
    },

    // 通过id删除
    deleteComment(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        get('/comment/deleteById', { id: row.id }).then((res) => {
          this.$message({ type: 'success', message: res.message })
          this.getComments()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消我们的操作'
        })
      })
    },
    
    

  }
}
</script>

<style>
.bottom{
text-align: center;
margin-top: 30px;
}
</style>
